<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

class User_caidan extends CI_Model {

	const DB_CAIDAN = 'caidan';
	const DB_CAIDAN_CAIPU = 'caidan_caipu';

	function __construct()
	{
		parent::__construct();
	
	}
	//$user_id 根据用户ID，菜单ID 查询 0为空
	//$caidan_id 查询菜单ID 0为空
	function get_caidan_uid($user_id)
	{
		$this->db->where('uid', $user_id);
		return  $this->db->get(self::DB_CAIDAN);
	}
	//验证菜单组是否已添加
	function get_caidan_caipu($caidan_id, $caipu_id, $uid = 0)
	{
		$array = array(
			'caidan_id' => intval($caidan_id),
			'caipu_id' 	=> intval($caipu_id),
			'uid' => intval($uid),
		);
		return  $this->db->get_where(self::DB_CAIDAN_CAIPU,$array);
	}
	//添加菜单信息
	function add_caidan_info($title = '', $desc = '', $user_id = 0)
	{
		$array = array(
			'uid' 		=> intval($user_id),
			'title' 	=> $title,
			'desc' 		=> $desc,
			'addtime' 	=> time(),
			'uptime' 	=> time()
		);
		$this->db->insert(self::DB_CAIDAN, $array);
		return $this->db->insert_id();
	}
	//插入菜单-菜谱关联表
	function add_caidan_caipu($caidan_id, $caipu_id, $uid = 0)
	{
		$caidan_ids = explode(",", $caidan_id);
		foreach ($caidan_ids as $caidanid) {
			$this->db->set('caidan_id', $caidanid); 
			$this->db->set('caipu_id', $caipu_id); 
			$this->db->set('uid', $uid); 
			$this->db->set('addtime', time()); 
            $this->db->insert(self::DB_CAIDAN_CAIPU);
        }
		//return $tid;
	}
	//删除我收藏的菜谱
	function del_caipu_caidan($caipu_id, $uid)
	{
		$array = array(
			'uid' 		=> intval($uid),
			'caipu_id' => intval($caipu_id)
		);
		return $this->db->delete(self::DB_CAIDAN_CAIPU, $array);
	}

}

/* End of file user_favorite.php */
/* Location: ./application/models/user/user_favorite.php */